#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void game()
{
    int r = rand() % 100 +1;
    int guess = 0;
    int count = 5;
    while (count)
    {
        printf("您有五次机会～\n");
        printf("请输入数字：\n");
        scanf("%d",&guess);
        if(guess > r)
        {
            printf("猜大了。");

        }
        else if (guess < r)
        {
            printf("猜小了\n");
        }
        else
        {
            printf("恭喜您，猜对了！\n");
            break;
        }

    count--;
    }
    if(count == 0)
    {
        printf("对不起，您的次数已用完。");
        printf("正确答案是：%d\n",r);
    }
    
}


void menu()
{
    printf("***********\n");
    printf("***********\n");
    printf("*  play:1 *\n");
    printf("*  exit:0 *\n");
    printf("***********\n");
    printf("***********\n");
}

int main()
{
    int input = 0;
    srand((unsigned  int)(time(NULL)));

    //循环
    do
    {
        menu();
        printf("请选择输入（0 或 1)：");
        scanf("%d",&input);
        switch(input)
        {
            case 1:
            game();
            break;

            case 0:
                    printf("游戏结束\n");
            break;

            default:
                    printf("选择错误，请重新选择~\n");

        }

    } while (input);

    return 0;
}